package view.notes;

import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.notes.Note;
import model.notes.Note.NoteName;
import model.notes.impl.NoteImpl;

public abstract class AbstractNoteGammeJPanel extends JPanel {

	JLabel choixLabel;
	JComboBox jComboBox;
	JButton okButton;

	JLabel gammeMajeureLabel;
	JLabel notesOfGammeMajeureLabel;

	JLabel gammeMajeureValue;
	JLabel notesOfGammeMajeureValue;

	JLabel gammeMineureLabel;
	JLabel notesOfGammeMineureLabel;
	
	JLabel gammeMineureValue;
	JLabel notesOfGammeMineureValue;

	
	public AbstractNoteGammeJPanel() {
		super();
		initComponent();
	}

	public AbstractNoteGammeJPanel(LayoutManager layout) {
		super(layout);
		initComponent();
	}

	private void initComponent() {

		this.choixLabel = new JLabel("Choisissez une note : ");
		this.choixLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));

		this.gammeMajeureLabel = new JLabel("Gamme majeure : ");
		this.gammeMajeureLabel.setBorder(BorderFactory.createEmptyBorder(20,
				0, 10, 0));
		this.gammeMajeureValue = new JLabel();
		
		this.notesOfGammeMajeureLabel = new JLabel("Note de la gamme majeure : ");
		this.notesOfGammeMajeureLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
		this.notesOfGammeMajeureValue = new JLabel();
		
		this.gammeMineureLabel = new JLabel("Gamme mineure : ");
		this.gammeMineureLabel.setBorder(BorderFactory.createEmptyBorder(20,
				0, 10, 0));
		this.gammeMineureValue = new JLabel();
		
		this.notesOfGammeMineureLabel = new JLabel("Note de la gamme mineure : ");
		this.notesOfGammeMineureLabel.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
		this.notesOfGammeMineureValue = new JLabel();
		
		
		this.jComboBox = new JComboBox(NoteName.values());
		this.okButton = new JButton("OK");
		this.okButton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				NoteName noteName = (NoteName) AbstractNoteGammeJPanel.this.jComboBox
						.getSelectedItem();
				Note note = new NoteImpl(noteName);
				StringBuilder gammeMajeureText = new StringBuilder();
				gammeMajeureText.append(note.getName());
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getSecondeMajeure(true));
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getTierceMajeure(true));
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getQuarte(true));
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getQuinte(true));
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getSixte(true));
				gammeMajeureText.append(" ");
				gammeMajeureText.append(note.getSeptiemeMajeure(true));
				AbstractNoteGammeJPanel.this.gammeMajeureValue.setText(gammeMajeureText.toString());
				
				StringBuilder gammeMineureText = new StringBuilder();
				gammeMineureText.append(note.getName());
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getSecondeMajeure(true));
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getTierceMineure(true));
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getQuarte(true));
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getQuinte(true));
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getQuinteMajeure(true));
				gammeMineureText.append(" ");
				gammeMineureText.append(note.getSeptiemeMineure(true));
				AbstractNoteGammeJPanel.this.gammeMineureValue.setText(gammeMineureText.toString());
			}
		});

		setLayoutAndAddCommponents();
	}

	protected abstract void setLayoutAndAddCommponents();
}
